package com.app.entity.bean;

import java.util.List;

/**
 * 分页类(用来封装分页展示的各种信息)
 */
public class Page<T> {
    public Page() {
    }

    public Page(int pageIndex, int pageSize, int totalCount, List<T> data) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;
        //计算总页数
         this.pageCount = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
    }

    //页码
     private int pageIndex;
     //页大小
     private int pageSize;
     //数据条数
     private int totalCount;
    //页数
     private int pageCount;
    //数据集合
     private List<T> data;
     //是否有上一页
    private boolean hasPrevious;
    //是否有下一页
    private boolean hasNext;

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageCount() {
        return pageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public boolean isHasPrevious() {
        //如果页码大于1，则有上一页
        return this.pageIndex > 1;
    }

    public boolean isHasNext() {
        //如果页码小于总页数，则有下一页
        return this.pageIndex < this.pageCount;
    }

}
